package com.rex.saas.utils;

import java.util.regex.Pattern;

public class PasswordValidator {
    // 校验密码是否满足四种组合要求
    public static boolean validatePassword(String password) {
        String regex = "^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[!@#$%^&*]).{8,}$";
        return Pattern.matches(regex, password);
    }

    // 校验密码是否至少包含三种组合
    public static boolean validatePasswordWithThreeTypes(String password) {
        int count = 0;
        if (password.matches(".*[A-Z].*")) count++;
        if (password.matches(".*[a-z].*")) count++;
        if (password.matches(".*\\d.*")) count++;
        if (password.matches(".*[!@#$%^&*].*")) count++;
        return password.length() >= 8 && count >= 3;
    }
}
